/******************************************************************************/
/*  Class I2C                                                                 */
/*  PO: S. Maslyakov, rusoil.9@gmail.com                                      */
/*                                                                            */
/*  Revision:     1.2                                                         */
/*  Date:         2010/12/26 01:09:33                                         */
/******************************************************************************/


#ifndef __I2C_H
#define __I2C_H


#include "data_types.h"
#include "I2c\i2c_def.h"


//==============================================================================
//  Class I2C
//==============================================================================
class I2C
{
public:
  static void Init_I2C();
  static bool_t Start(const uint8_t _addr, const uint32_t _len);
  static bool_t SetTxData(uint8_t * const _pSrc, const uint32_t _len);
  static bool_t GetRxData(uint8_t * const _pDst, const uint32_t _len);
  static void InterruptHandlerI2C1();
  inline static void SetTxByte(const uint8_t _data) {
      m_i2cBuff[0] = _data;
  }
  inline static void SetFlagOk() { m_flagOk = TRUE_T; }
  inline static void SetFlagEndI2C() { m_flagEndI2C = TRUE_T; }
  inline static uint8_t GetSlaveAddr() { return m_slaveAddr; }
  inline static uint32_t GetI2CLen() { return m_i2cLen; }
  inline static uint32_t GetI2CInd() { return m_i2cInd; }
  inline static void ClearI2CInd() { m_i2cInd = 0; }
  inline static void PopByte(const uint8_t _data) {
      m_i2cBuff[m_i2cInd++] = _data;
  }
  inline static uint8_t PushByte() { return m_i2cBuff[m_i2cInd++]; }

private:
  static uint8_t m_i2cBuff[I2C_BUFF_SIZE];
  static uint8_t m_slaveAddr;
  static uint32_t m_i2cLen;
  static uint32_t m_i2cInd;
  static volatile bool_t m_flagEndI2C;
  static volatile bool_t m_flagOk;
};
//==============================================================================
//==============================================================================


#endif